package com.yiqi.zhiyuan.feature.order.view;


import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.ViewGroup;

import com.flyco.tablayout.SlidingTabLayout;
import com.suozhang.framework.framework.BaseFragment;
import com.yiqi.zhiyuan.R;

import java.util.ArrayList;

import butterknife.BindView;


public class OrderFragment extends BaseFragment {
    @BindView(R.id.tb_order)
    SlidingTabLayout mTbOrder;
    @BindView(R.id.vp_order)
    ViewPager mVpOrder;
    private String mTitle;

    public static OrderFragment getInstance(String title) {
        OrderFragment sf = new OrderFragment();
        sf.mTitle = title;
        return sf;
    }

    private ArrayList<Fragment> mFragments = new ArrayList<>();

    private final String[] mTitles = {
            "未开始", "进行中", "已完成", "已关闭"
    };

    @Override
    public int attachLayoutRes() {
        return R.layout.fragment_order;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initView() {
        initTab();
    }

    private void initTab() {
        for (int i = 0; i < mTitles.length; i++) {
            mFragments.add(OrderListFragment.getInstance(i));
        }
        mVpOrder.setAdapter(new MyPagerAdapter(getChildFragmentManager()));
        mTbOrder.setViewPager(mVpOrder);
    }

    @Override
    protected void initData() {
    }

    @Override
    protected void initEvent() {

    }

    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {

        }
    }


}
